﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace MvcBoost.EntityFramework
{
    class LazyContextManager<TContext> : IDbContextManager<TContext>, IDelegatedDbContextManager<TContext>
        where TContext : DbContext
    {
        private TContext context = null;

        public TContext CreateContext()
        {
            if (context == null) throw new InvalidOperationException("This manager requires from other manager the responsibility of creating the context. No TContext has been provided");
            return context;
        }

        public void RemoveContext()
        {
            // Context has been given. Do nothing
        }

        public void SetContext(TContext context)
        {
            if (context == null) throw new ArgumentNullException("context");
            this.context = context;
        }
    }
}
